<?php

/**
 * 链式栈
 */
class LinkStack {
    public $data;
    public $next;
}

function InitLinkStack() {
    return null;
}

function PushLinkStack(?LinkStack &$stack, $x) {
    $s = new LinkStack();
    $s->data = $x;
    $s->next = $stack;
    $stack = $s;
}

function PopLinkStack(?LinkStack &$stack) {
    if ($stack == NULL) {
        return false;
    }
    $v = $stack->data;
    $stack = $stack->next;
    return $v;
}

$stack = InitLinkStack();

PushLinkStack($stack, 'a');
PushLinkStack($stack, 'b');
PushLinkStack($stack, 'c');

print_r($stack);
/*
LinkStack Object
(
    [data] => c
    [next] => LinkStack Object
        (
            [data] => b
            [next] => LinkStack Object
                (
                    [data] => a
                    [next] =>
                )
        )
)
*/

echo PopLinkStack($stack), PHP_EOL; // c
echo PopLinkStack($stack), PHP_EOL; // b
echo PopLinkStack($stack), PHP_EOL; // a

var_dump($stack); // NULL